package com.house.mapper;

import com.house.entity.House;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HouseMapper {

    // 添加房源
    @Insert("INSERT INTO t_house (title, description, price, address, landlord_id, created_at, updated_at) " +
            "VALUES (#{title}, #{description}, #{price}, #{address}, #{landlordId}, NOW(), NOW())")
    void addHouse(House house);

    // 修改房源信息
    @Update("UPDATE t_house SET title=#{title}, description=#{description}, price=#{price}, address=#{address}, updated_at=NOW() " +
            "WHERE id=#{id} AND landlord_id=#{landlordId}")
    void updateHouse(House house);

    // 删除房源
    @Delete("DELETE FROM t_house WHERE id=#{id} AND landlord_id=#{landlordId}")
    void deleteHouse(@Param("id") Long id, @Param("landlordId") Long landlordId);

    // 查询房东发布的所有房源
    @Select("SELECT * FROM t_house WHERE landlord_id=#{landlordId}")
    List<House> findHousesByLandlordId(@Param("landlordId") Long landlordId);
}

